{extend name="base/common"}

{block name="style"}
<link rel="stylesheet" href="/static/datepicker/bootstrap-datetimepicker.min.css">
<link rel="stylesheet" href="/static/iCheck/custom.css">
<link rel="stylesheet" href="/admin/css/chosen/chosen.css">
<style>

</style>
{/block}

{block name="page-header"}

{/block}

{block name="main"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="mail-box-header">
                <div class="pull-right tooltip-demo">
                    <a href="javascript:window.history.go(-1);" class="btn btn-white btn-sm"><i class="fa fa-reply"></i> 返回</a>
                </div>
                <h2>
                    取消假期 - {empty name="msg"}添加{else/}修改{/empty}
                </h2>
            </div>
            <div class="ibox-content all">
                <form id="form" class="form-horizontal" method="post">
                    <div class="form-group">
                        <div class="col-lg-1 text-right control-label">
                            <label>假别:</label>
                        </div>
                        <div class="col-lg-11">
                            <select class="form-control chosen-select " name="leave_id">
                                {volist name="leaveList" id="leave"}
                                {empty name="msg"}
                                <option value="{$leave.id}">{$leave.name}</option>
                                {else/}
                                <option value="{$leave.id}" {eq name="$msg['leave_id']" value="$leave.id"}selected{/eq}>{$leave.name}</option>
                                {/empty}
                                {/volist}
                            </select>
                        </div>
                    </div>
                   
                    <div class="form-group">
                        <div class="col-lg-1 text-right control-label">
                            <label>用户:</label>
                        </div>
                        <div class="col-lg-11">
                            <select class="form-control chosen-select" name="userid">
                                {volist name="userList" id="user"}
                                {empty name="msg"}
                                <option value="{$user.userid}">{$user.user_name}</option>
                                {else/}
                                <option value="{$user.userid}" {eq name="$msg['userid']" value="$user.userid"}selected{/eq}>{$user.user_name}</option>
                                {/empty}
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-lg-1 text-right control-label">
                            <label>取消假期原因:</label>
                        </div>
                        <div class="col-lg-11">
                            <input type="text" placeholder="请输入原因（必填）" class="form-control form_title" name="reason" value="{$msg.reason || default=''}">
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-lg-1 text-right control-label">
                            <label>限制生效时间:</label>
                        </div>
                        <div class="col-lg-11">
                            {empty name="msg"}
                            <input type="text" placeholder="请选择开始时间" class="form-control form_title datetimepicker" name="start_time" value="{$startTime}">
                            {else/}
                            <input type="text" placeholder="请选择开始时间" class="form-control form_title datetimepicker" name="start_time" value="{$msg.start_time}">
                            {/empty}
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-lg-1 text-right control-label">
                            <label>限制结束时间:</label>
                        </div>
                        <div class="col-lg-11">
                            {empty name="msg"}
                            <input type="text" placeholder="请选择结束时间" class="form-control form_title datetimepicker" name="end_time" value="{$endTime}">
                            {else/}
                            <input type="text" placeholder="请选择结束时间" class="form-control form_title datetimepicker" name="end_time" value="{$msg.end_time}">
                            {/empty}
                        </div>
                    </div>

                    <input type="hidden" name="id" value="{$msg.id || default=''}">
                    <div class="form-group">
                        <div class="col-lg-11 col-lg-offset-1">
                            <button class="btn btn-primary submit-btn post-put" type="button" target-form="form-horizontal" >提交</button>
                            <a class="btn btn-default" href="javascript:window.history.go(-1);">返回</a>
                        </div>
                    </div>
                    <div class="selblo"></div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script src="/static/uploadify/jquery.uploadify.min.js"></script>
<script src="/static/iCheck/icheck.min.js"></script>
<script src="/static/ueditor/ueditor.config.js"></script>
<script src="/static/ueditor/ueditor.all.min.js"></script>
<script src="/admin/js/chosen.jquery.js"></script>
<script src="/static/datepicker/bootstrap-datetimepicker.js"></script>
<script>
    $(function(){
        $('.chosen-select').chosen();
        //    单选按钮
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green'
        });

        highlight_subnav("{:Url('Leave/user_cancel')}");

        //    时间日历
        $( ".datetimepicker" ).datetimepicker( {
            language:  'cn',
            format: 'yyyy-mm-dd',
            minView: 2,
            forceParse: false,
            todayBtn: true,
            autoclose: true,
            todayHighlight: 1,
            minuteStep: 5,
            initialDate: new Date(),//初始化当前日期
        });

        //发布
        $(".post-put").off('click').on("click",function(){
            var it=$(this);
            var data = {
                id:$("input[name='id']").val(),
                leave_id:$("select[name='leave_id']").val(),
                userid:$("select[name='userid']").val(),
                reason:$("input[name='reason']").val(),
                start_time:$("input[name='start_time']").val(),
                end_time:$("input[name='end_time']").val(),
            };
            $.ajax({
                type:"post",
                url:$("#form").attr("action"),
                data:data,
                beforeSend: function(){
                    // Handle the beforeSend event
                    it.attr("disabled","true");
                },
                success:function(data){
                    if(data.code == 1){
                        if (data.url) {
                            updateAlert(data.msg + ' 页面即将自动跳转~','success');
                        }else{
                            updateAlert(data.msg ,'success');
                        }
                        it.prop('disabled','true');
                        it.prev().prop('disabled','true');
                        setTimeout(function(){
                            if (data.url) {
                                location.href=data.url;
                            } else {
                                location.reload();
                            }
                            it.removeAttr('disabled');
                            it.prev().removeAttr('disabled')
                        },2000);
                        it.attr("disabled","false");
                    } else {
                        updateAlert(data.msg, 'error');
                        it.attr('disabled','true');
                        it.prev().prop('disabled','true');
                        setTimeout(function(){
                            it.removeAttr('disabled');
                            it.prev().removeAttr('disabled')
                        },2000);
                    }
                }
            });
            return false;
        });
    })

</script>
{/block}